import { IWatermarkImageList } from '../interface';

class WaterMarkDao {
	private waterMarkList: IWatermarkImageList[] = [];
	private defaultWaterMarkList: IWatermarkImageList[] = [
		{
			id: -1,
			url: '',
			abbreviatedUrl: '', // 预览图片地址
			position: 1,
			fileName: 'nope.png',
			type: 'no',
			isDefault: true
		}
	];

	private waterMarkId: number = -1;

	public findAllWaterMarkList(): IWatermarkImageList[] {
		return this.waterMarkList;
	}

	public setWaterMarkList(watermarkList: IWatermarkImageList[]) {
		const list = [...this.defaultWaterMarkList, ...watermarkList];
		this.waterMarkList = list;
		console.log(this.waterMarkList);
	}

	public addWaterMark(background: IWatermarkImageList) {
		const { id } = background;
		if (!this.isExists(id)) {
			this.waterMarkList = [...this.waterMarkList, background];
			return true;
		}
		return false;
	}

	public isExists(id: number): boolean {
		const background = this.waterMarkList.find(item => item.id === id);
		return background ? true : false;
	}

	public removeWaterMark(id: number): boolean {
		if (this.isExists(id)) {
			this.waterMarkList = this.waterMarkList.filter(item => item.id !== id);
			return true;
		}
		return false;
	}

	public getWaterMarkId() {
		return this.waterMarkId;
	}

	public setWaterMarkId(id: number) {
		this.waterMarkId = id;
	}
}

export default WaterMarkDao;
